from s3 import renders
from s3 import parsers
from s3.handlers.delete_object import DeleteObjectHandler
from s3.negotiation import CusContentNegotiation
from s3.views.bucket_views import BucketViewSet
from s3.viewsets import S3CustomGenericViewSet


class PathBucketHostViewSet(S3CustomGenericViewSet):
    http_method_names = ['get', 'post', 'put', 'delete', 'head', 'options']
    renderer_classes = [renders.CusXMLRenderer]
    content_negotiation_class = CusContentNegotiation
    parser_classes = [parsers.S3XMLParser]

    def list(self, request, *args, **kwargs):
        """
        list objects (v1 && v2)
        get object metadata
        ListMultipartUploads
        """
        return BucketViewSet().list(request=request, *args, **kwargs)

    def update(self, request, *args, **kwargs):
        """
         create bucket
        """
        return BucketViewSet().update(request=request, *args, **kwargs)

    def create(self, request, *args, **kwargs):
        """
        DeleteObjects
        """

        if 'delete' in request.query_params:
            return DeleteObjectHandler.delete_objects(request=request, view=self)

    def destroy(self, request, *args, **kwargs):
        """
          delete bucket
        """
        return BucketViewSet().destroy(request=request, *args, **kwargs)

    def head(self, request, *args, **kwargs):
        """
        head bucket
        """
        return BucketViewSet().head(request=request, *args, **kwargs)
